package org.yaac.server.egql;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

/**
 * @author Max Zhu (thebbsky@gmail.com)
 *
 */
public class Command implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * 
	 */
	private List<Statement> statements;
	
	/**
	 * 
	 */
	public Command() {
		this.statements = new LinkedList<Statement>();
	}

	/**
	 * attach raw statement to parsed statement, this is used by ANTLR
	 * 
	 * @param e
	 * @param rawStatement
	 * @return
	 */
	public Command add(Statement e, String rawStatement) {
		e.setRawStatement(rawStatement);
		statements.add(e);
		return this;
	}
	
	/**
	 * @return
	 */
	public List<Statement> getStatements() {
		return statements;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((statements == null) ? 0 : statements.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Command other = (Command) obj;
		if (statements == null) {
			if (other.statements != null)
				return false;
		} else if (!statements.equals(other.statements))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Command [statements=" + statements + "]";
	}
}
